"""
重点：封装登陆注册模块被测接口
"""
from config import HOST, log


class ApiRegisterLogin:
    # 初始化
    def __init__(self, session):
        # 获取session对象
        self.session = session
        # 获取图片验证码url
        self.url_img_code = HOST + "/commom/public/{}"
        # 获取短信验证码url
        self.url_phone_code = HOST + "/member/public"
        # 注册接口url
        self.url_register = HOST + "/member/public/reg"
        # 登录接口url
        self.url_login = HOST + "/member/public/reg"
        # 查询登陆状态url
        self.url_login_status = HOST + "/member/public/reg"

    # 1,获取图片验证码 封装
    def api_img_code(self, random):
        log.info("")
        # 调用get方法
        return self.session.get(url=self.url_img_code.format(random))

    # 2，获取短信验证码 封装
    def api_phone_code(self, phone, imgCode):
        # 1）定义请求参数
        data = {
            "phone": phone,
            "imgCode": imgCode,
            "type": "reg"
        }
        # 2）定义请求方法
        return self.session.post(url=self.url_phone_code, data=data)

    # 3，注册接口 封装
    def api_register(self, phone, password, phone_code, verifcode):
        # 1）定义请求参数
        data = {
            "phone": phone,
            "password": password,
            "verifycode": verifcode,
            "phone_code": phone_code,
            "dy_server": "on",
            "invite_phone": ""
        }
        # 2）定义请求方法
        return self.session.post(url=self.url_register, data=data)

    # 4，登录接口 封装
    def api_login(self, phone, password):
        # 1）定义请求参数
        data = {
            "phone": phone,
            "password": password,
        }
        # 2）定义请求方法
        return self.session.post(url=self.url_login, data=data)

    # 5，查询登录状态 封装
    def api_login_status(self):
        return self.session.post(url=self.url_login_status)
